<?php

use yii\db\Migration;
use yii\db\Schema;

/**
 * Class m210422_143334_CREATE_DB_INIT
 */
class m210422_143334_CREATE_DB_INIT extends Migration
{
    /**
     * {@inheritdoc}
     */
    public function safeUp()
    {

        $tableOptions = 'CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE=InnoDB';
        // 管理员表 
        $this->createTable('admin', [
            "adid" =>           Schema::TYPE_PK,
            "adname" =>         Schema::TYPE_STRING.    "(100) NOT NULL COMMENT '名字'",
            "adpass" =>         Schema::TYPE_STRING.    "(45) NOT NULL COMMENT '密码'",
            "status" =>         Schema::TYPE_INTEGER.   "(1) DEFAULT  '1' COMMENT '1正常  2禁用'",
            "create_time"=>     Schema::TYPE_DATETIME.  " NULL",
            "updated_at" =>     Schema::TYPE_TIMESTAMP. " NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP",
        ], $tableOptions);


         // 公告表 
        $this->createTable('detail', [
            "detail_id" =>      Schema::TYPE_PK,
            "detail_type" =>    Schema::TYPE_STRING.    "(45) NULL COMMENT '描述类型'",
            "detai_com" =>      Schema::TYPE_STRING.    "(500)  NULL COMMENT '描述内容'",
            "detail_time"=>     Schema::TYPE_DATETIME.  " NULL",
            "updated_at" =>     Schema::TYPE_TIMESTAMP. " NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP",
        ], $tableOptions);


         // 学生信息表 
        $this->createTable('user', [
            "id" =>       Schema::TYPE_PK,
            "schoolid" => Schema::TYPE_INTEGER.    "(12) NOT NULL COMMENT '学号'",
            "age" =>      Schema::TYPE_INTEGER.    "(11) NOT NULL COMMENT '年龄'",
            "password" => Schema::TYPE_STRING.     "(45) NOT NULL COMMENT '密码'",
            "sex" =>      Schema::TYPE_INTEGER.    "(1) DEFAULT '1' COMMENT '性别'",
            "classname" => Schema::TYPE_STRING.    "(45) NOT NULL ",
            "sign" =>         Schema::TYPE_STRING.   "(1000) NULL COMMENT '1正常  2禁用'",
            "create_time"=>     Schema::TYPE_DATETIME.  " NULL",
            "updated_at" =>     Schema::TYPE_TIMESTAMP. " NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP",
        ], $tableOptions);

    }

    /**
     * {@inheritdoc}
     */
    public function safeDown()
    {
        echo "m210422_143334_CREATE_DB_INIT cannot be reverted.\n";

        return false;
    }

    /*
    // Use up()/down() to run migration code without a transaction.
    public function up()
    {

    }

    public function down()
    {
        echo "m210422_143334_CREATE_DB_INIT cannot be reverted.\n";

        return false;
    }
    */
}
